<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>模板字符串</title>
  <script type="text/javascript">
    // 模板字符串能将原生的换行正常输出
    let str = `for (int i = 0; i < 5; i++) {
      System.out.println(i);
    }`;
    console.log("str:", str);
    // 模板字符串能插入变量和表达式  ${变量名/表达式}
    let name = "tom";
    let str2 = `name=${name}`;
    console.log("str2:", str2);
    let n1 = 10;
    let n2 = 20;
    let str3 = `${n1} + ${n2} = ${n1 + n2}`;
    console.log("str3:", str3);
    // 模板字符串能在字符串内调用函数
    function sayHi(name) {
      return `Hi, ${name}!`;
    }
    let str4 = `调用sayHi('tom')--${sayHi('tom')}`;
    let str5 = `调用sayHi(name)--${sayHi(name)}`;
    console.log("str4:", str4);
    console.log("str5:", str5);
  </script>
</head>
<body>
</body>
</html>
